package com.qf.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import java.util.Properties;

/**
 * @author 29125
 * @version V1.0
 * @Project java2203
 * @Package com.qf.utils
 * @Description:
 * @Date 2022/5/22 20:10
 */
public class DBUtil {
    //连接数据源对象
    private static DruidDataSource dataSource;
    //获取数据源
    public static DruidDataSource getDataSource(){
        return dataSource;
    }
    //读取配置文件的内容  在src下设置druid.prop文件
    static {
        try {
            //创建容器
            Properties prop =new Properties();
            prop.load(DBUtil.class.getResourceAsStream("/druid.prop"));
            //创建连接池对象
            dataSource= (DruidDataSource) DruidDataSourceFactory.createDataSource(prop);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    //构造方法私有化
    private DBUtil(){}
}
